var User = {
    config: function (options) {
        this.jquery = options.jquery;
        this.fmsUtil = options.fmsUtil;
        this.base64 = options.base64;
    },
    method: function () {
        var config = this;
        var $ = config.jquery;
        var fmsUtil = config.fmsUtil;
        var base64 = config.base64;
        var common = {

            //保存信息
            save: function (data) {
                var user = common.getUser(userKey);
                if (user == undefined || user == null || user == "null") {
                    $.cookie(userKey, base64.encode(data), {expires: 1, path: '/'});
                    common.goLocation();
                } else {
                    common.goLocation();
                }
            },
            go: function (data) {
                var object = JSON.parse(data)
                if (object.isAdmin == true) {
                    common.goAdmin();
                } else {
                    common.goLocation();
                }
            },
            getUser: function (userKey) {
                var user = $.cookie(userKey);
                return user;
            },
            //跳转到主页
            goLocation: function () {
                fmsUtil.replaceHref(pathUrl + "/main.html");
            }
            ,
            goAdmin: function () {
                fmsUtil.replaceHref(pathUrl + "/html/operate/main.html");
            },
            isLogin: function () {
                if(common.getUser(userKey)!='null' && common.getUser(userKey)!=undefined ){
                    var user = base64.decode(common.getUser(userKey));
                    if (user !== undefined && user !== "null") {
                        // var object = JSON.parse(user);
                        // if (object.isAdmin == true) {
                        //     common.goAdmin();
                        // } else {
                            common.goLocation();
                        // }
                    }
                }
            },

            /***
             * 删除
             * @param callBack
             */
            delUser: function (callBack) {
                // debugger
                var user = common.getUser(userKey);
                if (user != undefined || user != "null") {
                    $.cookie(userKey, null);
                }
                if (callBack !== undefined) {
                    callBack();
                }
            },
            logOut: function () {
                $(".main-logOut").click(function () {
                    common.delUser(function () {
                        fmsUtil.replaceHref(pathUrl + "/login.html")
                    })
                })
            },
            review:function () {
                console.log(location.href);
                $("#reload").click(function () {
                    var currentSrc = $("#iframe").attr('src')
                    $("#iframe").attr('src',currentSrc);

                })
            },
            //判断是否能够进入
            initMain: function () {
                /*  var user=common.getUser(userKey);
                  if(user==undefined  || user=="null"){
                      fmsUtil.replaceHref(pathUrl+"/login.html")
                  }else{
                      var userStr= base64.decode(user);
                      var object=JSON.parse(userStr);
                      $(".layui-side-logo p").html(object.userName);
                  }
                  */

                common.logOut();
                common.review();
            },
            clearAllCookie: function () {
                $.cookie(userKey, '', {expires: -1});
            }
        };
        return common;
    }
};


